﻿using System.Collections;
using System.Configuration;
using System.Text;
using MPMovieCatalog.Util;

namespace MPMovieCatalog.Configuration.Sections
{
    public sealed class PrintSection : PropertySection
    {
        [ConfigurationProperty("title")]
        private PropertyElement m_title
        {
            get
            {
                PropertyElement title = (PropertyElement)base["title"];
                return title;
            }

            set
            {
                base["title"] = value;
            }
        }

        [ConfigurationProperty("fontName")]
        private PropertyElement m_fontName
        {
            get
            {
                PropertyElement fontName = (PropertyElement)base["fontName"];
                return fontName;
            }

            set
            {
                base["fontName"] = value;
            }
        }

        [ConfigurationProperty("fontSize")]
        private PropertyElement m_fontSize
        {
            get
            {
                PropertyElement fontSize = (PropertyElement)base["fontSize"];
                return fontSize;
            }

            set
            {
                base["fontSize"] = value;
            }
        }

        [ConfigurationProperty("fontColor")]
        private PropertyElement m_fontColor
        {
            get
            {
                PropertyElement fontColor = (PropertyElement)base["fontColor"];
                return fontColor;
            }

            set
            {
                base["fontColor"] = value;
            }
        }

        [ConfigurationProperty("shadingEnabled")]
        private PropertyElement m_shadingEnabled
        {
            get
            {
                PropertyElement shadingEnabled = (PropertyElement)base["shadingEnabled"];
                return shadingEnabled;
            }

            set
            {
                base["shadingEnabled"] = value;
            }
        }

        [ConfigurationProperty("showThumb")]
        private PropertyElement m_showThumb
        {
            get
            {
                PropertyElement showThumb = (PropertyElement)base["showThumb"];
                return showThumb;
            }

            set
            {
                base["showThumb"] = value;
            }
        }

        [ConfigurationProperty("fields")]
        private PropertyElement m_fields
        {
            get
            {
                PropertyElement fields = (PropertyElement)base["fields"];
                return fields;
            }

            set
            {
                base["fields"] = value;
            }
        }

        public string Title
        {
            get
            {
                return m_title.Value;
            }
            set
            {
                SetProperty("title", value);
            }
        }

        public string FontName
        {
            get
            {
                return m_fontName.Value;
            }
            set
            {
                SetProperty("fontName", value);
            }
        }

        public decimal FontSize
        {
            get
            {
                return m_fontSize.ValueAsLong;
            }
            set
            {
                SetProperty("fontSize", value.ToString());
            }
        }

        public string FontColor
        {
            get
            {
                return m_fontColor.Value;
            }
            set
            {
                SetProperty("fontColor", value);
            }
        }

        public bool ShadingEnabled
        {
            get
            {
                return m_shadingEnabled.ValueAsBoolean;
            }
            set
            {
                SetProperty("shadingEnabled", value.ToString().ToLower());
            }
        }

        public bool ShowThumb
        {
            get
            {
                return m_showThumb.ValueAsBoolean;
            }
            set
            {
                SetProperty("showThumb", value.ToString().ToLower());
            }
        }

        public ArrayList Fields
        {
            get
            {
                ArrayList fields = new ArrayList();
                foreach (string name in m_fields.Value.Split(';'))
                {
                    Field field = MPMovieCatalog.Util.Fields.FindFieldByName(name);
                    if (field != null)
                    {
                        fields.Add(field);
                    }
                }

                return fields;
            }
            set
            {
                StringBuilder sb = new StringBuilder();
                foreach (Field field in value)
                {
                    if (sb.Length > 0)
                    {
                        sb.Append(";");
                    }
                    sb.Append(field.Name);
                }
                SetProperty("fields", sb.ToString());
            }
        }
    }
}
